$(function () {
    if (businessName== 'null' || businessName== '' ){
        toastr.error("还未登录,请先登录")
        return null
    }
    var mydate = new Date();
    var str = '"' + mydate.getFullYear() + '"';
    console.info("str"+str);
    $('#datetimepicker1').datetimepicker({
        format: 'YYYY',
        locale: moment.locale('zh-cn'),
        defaultDate: str
    });
    var picker1 = $('#datetimepicker1').datetimepicker({
        format: 'YYYY',
        locale: moment.locale('zh-cn')
    });

    // 基于准备好的dom，初始化echarts实例
    var mylineNumChart = echarts.init(document.getElementById('bookLineNum'));
    // 指定图表的配置项和数据
    var mylineNumoption = {
        title: {
            text: '收入统计', //标题文本内容
            x:'center'
        },
        toolbox: { //可视化的工具箱
            show: true,
            feature: {
                dataView: { //数据视图
                    show: true,
                    height: 400
                },
                /* restore: { //重置
                     show: true
                 },*/
                /*    dataZoom: { //数据缩放视图
                        show: true
                    },*/
                saveAsImage: {//保存图片
                    show: true
                },
                magicType: {//动态类型切换
                    type: ['bar', 'line']
                }
            }
        },
        tooltip: { //弹窗组件
            show: true
        },
        xAxis: {
            data: []
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: 'bar',
            data: []
        }]

    };
    // 使用刚指定的配置项和数据显示图表。
    mylineNumChart.setOption(mylineNumoption);

    /*var year=new Date().getFullYear();*/
    var year=$('#inTimeSelect').val();
    var months=[];//用来盛放X轴坐标值：月份
    var monthsPrice=[];
    $.ajax({
        url : ctx +"businessHigh/getTotalInPrice?year="+year,
        type:"post",
        dataType:"json",
        success :function (data) {
            for (var i = 0; i < data.length;i++) {
                months.push(data[i].total_month+"月");
                monthsPrice.push(data[i].total_price);
            }
            mylineNumChart.hideLoading();
            mylineNumChart.setOption({        //加载数据图表
                xAxis: {
                    name: '月',
                    data: months,
                    type: 'category',
                    axisLabel: {
                        interval: 0,//横轴信息全部显示
                        rotate: 0,//-30度角倾斜显示
                    },
                },
                series: [{
                    data: monthsPrice
                }]
        });
        }
    })
    $('#search_btn').click(function () {
        var newMonths=[];//用来盛放X轴坐标值：月份
        var newmonthsPrice=[];
        var newyear=$('#inTimeSelect').val()
        $.ajax({
            url : ctx +"businessHigh/getTotalInPrice?year="+newyear,
            type:"post",
            dataType:"json",
            success :function (data) {
                for (var i = 0; i < data.length;i++) {
                    newMonths.push(data[i].total_month+"月");
                    newmonthsPrice.push(data[i].total_price);
                }
                mylineNumChart.hideLoading();
                mylineNumChart.setOption({        //加载数据图表
                    xAxis: {
                        name: '月',
                        data: newMonths,
                        type: 'category',
                        axisLabel: {
                            interval: 0,//横轴信息全部显示
                            rotate: 0,//-30度角倾斜显示
                        },
                    },
                    series: [{
                        data: newmonthsPrice
                    }]
                });
            }
        })
    })
})